import 'package:flutter/material.dart';
import 'package:flutterdemo/main.dart';
import 'package:flutterdemo/smartform/container/StackPage.dart';

class HomePage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return HomeState();
  }

}

/// 需求：
/// 1.创建一个路由列表，用于跳转各个demo page
/// 2.管理各个page的生命周期
class HomeState extends State<HomePage>{

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
     return Container(
       child: _buildList(),
       decoration: BoxDecoration(color: Colors.white),
       margin: EdgeInsets.all(5),
     );
  }
  
  Widget _buildList(){

    var routeList = routesNameMap;

    List<MapEntry<String, String>> listData = [];
    for (var entry in routeList.entries) {
      listData.add(entry);
    }
    Widget listView = ListView.separated(itemBuilder: (context, index){
        return _buildItem(context, listData[index].value, listData[index].key);
      },
      itemCount: routeList.length,
      separatorBuilder: (BuildContext context, int index) {
      return Divider( // 使用Divider作为分隔符Widget
        color: Colors.grey, // 分隔线的颜色
        height: 1.0, // 分隔线的高度
      ); },


    );
    return listView;
  }

  Widget _buildItem(BuildContext context, String routeName, String routeKey){
    var width = MediaQuery.of(context).size.width;

    Widget item = GestureDetector(
      onTap: ()=>{

      },
      child: Container(
        width: width - 50,
        // child: Align(
        //   alignment: Alignment.center,
          child: TextButton(
            onPressed: () => {
              Navigator.pushNamed(context, routeKey)
            },
            child: Text(
              routeName,
              style: TextStyle(color: Colors.white, fontSize: 18, decoration: TextDecoration.none),
            ),
            style: ElevatedButton.styleFrom(
              primary: Colors.blue, // 设置背景颜色为蓝色
            ),
          ),

        ),
      // ),
    );

    return item;
  }

}